{% import "TopxiaWebBundle::macro.html.twig" as web_macro %}

{% set thread = thread|default(null) %}
{% set isUpdate = thread ? 1 : 0 %}

{% include 'TopxiaWebBundle:Thread/Part:thread-crumbs.html.twig' with {target:target, thread:thread,type:type, isUpdate:isUpdate} %}

<form id="thread-form" class="form-horizontal" method="post" 
  {% if thread %}
    action="{{ path(target.type ~ '_thread_update', {(target.type ~ 'Id'): target.id, threadId:thread.id}) }}"
  {% else %}
    action="{{ path(target.type ~ '_thread_create', {(target.type ~ 'Id'): target.id, type:type}) }}"
    {% endif %}
  >
  
  {% if type =='question' %}
    <div class="form-group">
      <div class="col-md-12">
        <input type="type" id="title" class="form-control" placeholder="问题" ata-display="问题" name= "title" value="{{ thread.title|default('') }}">
        </div>
    </div>
  {% endif %}
  
  {% if type =='discussion' %}
    <div class="form-group">
        {# <label for="title" class="col-sm-2 control-label">话题标题</label> #}
      <div class="col-md-12">
        <input type="type" id="title" class="form-control" placeholder="话题标题" ata-display="话题标题" name= "title" value="{{ thread.title|default('') }}">
        </div>
    </div>
  {% endif %}

  {% if type == 'event' %}
    <div class="form-group">
        <label for="title" class="col-sm-2 control-label">活动标题</label>
      <div class="col-sm-7">
        <input type="type" id="title" class="form-control" placeholder="活动标题" ata-display="标题" name= "title" value="{{ thread.title|default('') }}">
        </div>
    </div>

    <div class="js-event-content" {% if type != 'event' %}style="display:none;" {% endif %}>
      <div class="form-group">
        <div class="col-md-2 control-label">
          <label for="startTime">活动时间</label>
        </div>
        <div class="col-md-7 controls">
          <input type="text" id="startTime" class="form-control" placeholder="活动开始时间" name="startTime" value="{% if thread.startTime|default(null) %}{{ thread.startTime|date('Y-m-d H:i') }}{% endif %}">
          </div>
      </div>

      <div class="form-group">
        <div class="col-md-2 control-label">
          <label for="location">活动地点</label>
        </div>
        <div class="col-md-7 controls">
          <input type="text" id="location" class="form-control" placeholder="活动地点" name= "location" value="{{ thread.location|default('') }}">
          </div>
      </div>

      <div class="form-group">
        <label for="inputTitle" class="col-sm-2 control-label">封面图片</label>
        <div class="col-md-7 controls">
          <input type="text" class="form-control" name="actvityPicture" value="{{ thread.actvityPicture|default('') }}" placeholder="推荐图片大小200*112">
        </div>
        <div class="col-sm-2">
          <a class="btn btn-default btn-block" id="js-activity-uploader" data-upload-token="{{ upload_token('classroom', 'image') }}">浏览...</a>
        </div>
      </div>

      {% set maxUsers = thread.maxUsers|default(null) %}
      <div class="form-group">
        <div class="col-md-2 control-label">
          <label for="maxUsers">最大人数</label>
        </div>
        <div class="col-md-7 controls">
          <input type="text" id="maxUsers" class="form-control" placeholder="不限" name="maxUsers" value="{% if maxUsers and maxUsers != 0 %}{{ maxUsers }}{% endif %}">
          </div>
      </div>
    </div>
  {% endif %}
 
  <div class="form-group">
    {% if type == 'event' %}
        <div class="controls col-md-2"></div>
        <div class="controls col-md-7">
          <textarea id="thread-content-field" class="form-control" rows="15" data-display="内容" name="content"
            data-image-upload-url="{{ path('editor_upload', {token:upload_token('default')}) }}" data-image-download-url="{{ path('editor_download', {token:upload_token('course')}) }}">{{ thread.content|default('') }}</textarea>
        </div>
    {% else %}
        {# <div class="controls col-md-2"></div> #}
        <div class="controls col-md-12">
          <textarea id="thread-content-field" class="form-control" rows="15" data-display="内容" name="content"
            data-image-upload-url="{{ path('editor_upload', {token:upload_token('default')}) }}" data-image-download-url="{{ path('editor_download', {token:upload_token('course')}) }}">{{ thread.content|default('') }}</textarea>
        </div>
    {% endif %}
    
  </div>

  <div class="clearfix">
      {% if thread %}
        <button type="submit" class="btn btn-primary pull-right">保存</button>
        <a href="{{ path(target.type ~ '_thread_show', {(target.type ~ 'Id'): target.id, threadId:thread.id}) }}" class="btn btn-link pull-right color-gray">取消</a>

      {% else %}
        <button type="submit" class="btn btn-primary pull-right">发表</button>
        <a href="{{ path(target.type ~ '_threads', {(target.type ~ 'Id'): target.id}) }}" class="btn btn-link pull-right color-gray">取消</a>

      {% endif  %}
  </div>

  <input type="hidden" name="_csrf_token" value="{{ csrf_token('site') }}">
  <input type="hidden" name="type" value="{{ type }}">
</form>
